import { Component, OnInit ,Inject,DoCheck} from '@angular/core';
import {MAT_DIALOG_DATA,MatDialogRef} from "@angular/material"
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {ChangeDetectionStrategy} from "@angular/core"
@Component({
  selector: 'app-new-project',
  templateUrl: './new-project.component.html',
  styleUrls: ['./new-project.component.scss'],
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class NewProjectComponent implements OnInit,DoCheck {
  title:string='';
  coverImages = [];
  form:FormGroup;
  constructor(
    @Inject(MAT_DIALOG_DATA) private data,
    private dialogRef:MatDialogRef<NewProjectComponent>,
    private fb:FormBuilder
  ) {

  }

  ngOnInit() {
    this.coverImages = this.data.thumbnails;
    if(this.data.project){
      this.form = this.fb.group({
        name:[this.data.project.name,Validators.required],
        desc:[this.data.project.desc],
        coverImg:[this.data.project.coverImg]
      });
      this.title = '修改项目';
    }else{
      this.form = this.fb.group({
        name:['',Validators.required],
        desc:[''],
        coverImg:[this.data.img]
      });
      this.title = '新增项目';
    }
  }
  onSubmit({value,valid},ev:Event){
    if(!valid){
      return
    }
    this.dialogRef.close(value);
  }
  onClose(){
    this.dialogRef.close();
  }
  ngDoCheck(){
    console.log('projectnewproject'+'本组件变更检测完毕')
  }
}
